package info.wangyuan.agent.controller.admin;

import info.wangyuan.agent.entity.po.SystemPrompts;
import info.wangyuan.agent.service.curd.PromptService;
import info.wangyuan.agent.utils.Result;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 管理员提示词管理
 *
 * @author Albert
 * @since 2025-07-14 02:33:07
 */
@RestController
@CrossOrigin(origins = "*")
@RequestMapping("/admin/prompt")
public class PromptController {

    private final PromptService promptService;

    public PromptController(PromptService promptService) {
        this.promptService = promptService;
    }

    /**
     * 获取提示词列表
     */
    @GetMapping("/list")
    public Result<List<SystemPrompts>> getSystemPromptsList() {
        return Result.success(promptService.list());
    }

    /**
     * 提示词添加
     */
    @PostMapping("/add")
    public Result<Void> addSystemPrompts(@RequestBody @Valid SystemPrompts systemPrompts) {
        promptService.save(systemPrompts);
        return Result.success();
    }

    /**
     * 提示词修改
     */
    @PostMapping("/update")
    public Result<Void> updateSystemPrompts(@RequestBody @Valid SystemPrompts systemPrompts) {
        promptService.updateById(systemPrompts);
        return Result.success();
    }

    /**
     * 提示词删除
     */
    @DeleteMapping("/{id}")
    public Result<Void> deleteSystemPrompts(@PathVariable @NotNull(message = "id不能为空") Integer id) {
        promptService.canDelete(id);
        return Result.success();
    }

}
